
const mediaQuery = window.matchMedia('(max-width: 600px)');
if (mediaQuery.matches) {
    // 小于600px

    var eprev = document.querySelector('.prev');
var enext = document.querySelector('.next');
var esico = document.getElementById('icolist').getElementsByTagName('li');
var eicolist = document.querySelector('#icolist');
var eimglist = document.querySelector('#imglist');
var left = 0;
var timer;
run();
// 时间
function run() {
    if (left <= -1440) {
        left = 0;
    }
    var m = Math.floor(-left / 480);
    imglist.style.marginLeft = left + 'px';
    var n = (left % 480 == 0) ? n = 2400 : n = 10
    left -= 10;
    timer = setTimeout(run, n);
    icochange(m)
}
// 图片定位
function imgchange(n) {
    let lt = -(n * 480);
    imglist.style.marginLeft = lt + 'px'
    left = lt;
}
eprev.onclick = function () {
    let prevgo = Math.floor(-left / 480) - 1;
    if (prevgo == -1) {
        prevgo = 2;
    }
    imgchange(prevgo);
}
enext.onclick = function () {
    let nextgo = Math.floor(-left / 480) + 1;
    if (nextgo == 3) {
        nextgo = 0;
    }
    imgchange(nextgo);
}
function icochange(m) {
    for (let index = 0; index < esico.length; index++) {
        esico[index].style.backgroundColor = '';
    }
    if (m < esico.length) {
        esico[m].style.backgroundColor = 'red';
    }
}
eicolist.onclick = function () {
    var tg = event.target;
    let ico = tg.innerHTML - 1;
    imgchange(ico);
    icochange(ico);
}
eimglist.onmouseover = function () {
    clearTimeout(timer);
}
eimglist.onmouseout = function () {
    run();
}
} else {
// 大于600px
var eprev = document.querySelector('.prev');
var enext = document.querySelector('.next');
var esico = document.getElementById('icolist').getElementsByTagName('li');
var eicolist = document.querySelector('#icolist');
var eimglist = document.querySelector('#imglist');
var left = 0;
var timer;
run();
// 时间
function run() {
    if (left <= -2100) {
        left = 0;
    }
    var m = Math.floor(-left / 700);
    imglist.style.marginLeft = left + 'px';
    var n = (left % 700 == 0) ? n = 2400 : n = 10
    left -= 10;
    timer = setTimeout(run, n);
    icochange(m)
}
// 图片定位
function imgchange(n) {
    let lt = -(n * 700);
    imglist.style.marginLeft = lt + 'px'
    left = lt;
}
eprev.onclick = function () {
    let prevgo = Math.floor(-left / 700) - 1;
    if (prevgo == -1) {
        prevgo = 2;
    }
    imgchange(prevgo);
}
enext.onclick = function () {
    let nextgo = Math.floor(-left / 700) + 1;
    if (nextgo == 3) {
        nextgo = 0;
    }
    imgchange(nextgo);
}
function icochange(m) {
    for (let index = 0; index < esico.length; index++) {
        esico[index].style.backgroundColor = '';
    }
    if (m < esico.length) {
        esico[m].style.backgroundColor = 'red';
    }
}
eicolist.onclick = function () {
    var tg = event.target;
    let ico = tg.innerHTML - 1;
    imgchange(ico);
    icochange(ico);
}
eimglist.onmouseover = function () {
    clearTimeout(timer);
}
eimglist.onmouseout = function () {
    run();
}
}
// 轮播图结束